//
//  JFDatabaseTestDBSqlite.m
//  JFDatabase
//
//  Created by 季成 on 14-2-8.
//  Copyright (c) 2014年 季成. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "JFDatabase.h"

@interface JFDatabaseTestDBSqliteModel1 : NSObject

@property (nonatomic,copy) NSString *_id;
@property (nonatomic) int pInt;
@property (nonatomic) double pDouble;
@property (nonatomic,copy) NSString *pString;
@property (nonatomic,strong) id pOther;

@end

@implementation JFDatabaseTestDBSqliteModel1

@end

@interface JFDatabaseTestDBSqliteModel2 : NSObject

@property (nonatomic,copy) NSString *_id;
@property (nonatomic) int pInt;
@property (nonatomic) double pDouble;
@property (nonatomic,copy) NSString *pString;
@property (nonatomic,strong) id pOther;

@end

@implementation JFDatabaseTestDBSqliteModel2

@end

@interface JFDatabaseTestDBSqlite : XCTestCase

@end

@implementation JFDatabaseTestDBSqlite

- (void)setUp
{
    [super setUp];
}

- (void)tearDown
{
    [super tearDown];
}

- (void)testCreateTableSqls
{
    {
        NSArray *sqls = [JFDBSqlite createTableSqls:nil];
        XCTAssert(sqls == nil);
    }
    
    {
        NSArray *sqls = [JFDBSqlite createTableSqls:@[]];
        XCTAssert(sqls != nil && sqls.count == 0);
    }
    
    {
        NSArray *sqls = [JFDBSqlite createTableSqls:@[[JFDatabaseTestDBSqliteModel1 class]]];
        XCTAssert(sqls != nil && sqls.count == 1
                  && [sqls[0] isKindOfClass:[NSString class]]
                  && [@"create table JFDatabaseTestDBSqliteModel1(_id text primary key,pInt int,pDouble double,pString text)" isEqualToString:sqls[0]]);
    }
    
    {
        NSArray *sqls = [JFDBSqlite createTableSqls:@[[JFDatabaseTestDBSqliteModel1 class],[JFDatabaseTestDBSqliteModel2 class]]];
        XCTAssert(sqls != nil && sqls.count == 2
                  && [sqls[0] isKindOfClass:[NSString class]]
                  && [@"create table JFDatabaseTestDBSqliteModel1(_id text primary key,pInt int,pDouble double,pString text)" isEqualToString:sqls[0]]
                  && [sqls[1] isKindOfClass:[NSString class]]
                  && [@"create table JFDatabaseTestDBSqliteModel2(_id text primary key,pInt int,pDouble double,pString text)" isEqualToString:sqls[1]]);
    }
}

- (void)testInitWithPath
{
    NSString *testPath = @"testPath";
    JFDBSqlite *sqlite = [[JFDBSqlite alloc]initWithPath:testPath];
    XCTAssert([sqlite db] == NULL && [[sqlite path] isEqualToString:testPath]);
}

@end
